/*
 *  uiSubmenu.cpp
 *  trail-map-editor
 *
 *  Created by Giorgio Tino on 3/24/13.
 *  Copyright 2013 __MyCompanyName__. All rights reserved.
 *
 */

#include "ui.h"

uiSubmenu::uiSubmenu(const char* str)
: items(0)
{
	this->name = ulStrDup(str);
}

uiSubmenu::~uiSubmenu()
{
	if(this->name)
	{
		delete[] name;
		name = NULL;
	}
	
	if(this->items)
	{
		for(unsigned int i = 0; i < items->getNumEntities(); i++)
		{
			uiSubmenuItem* item = (uiSubmenuItem*)items->getEntity(i);
			delete item;
		}
		
		delete this->items;
		this->items = NULL;
	}
}

void uiSubmenu::addItem(const char* name, const char* legend)
{
	uiSubmenuItem* item = new uiSubmenuItem(name, legend);
	
	if(!this->items)
	{
		this->items = new ulList();
	}
	
	this->items->addEntity(item);
}

unsigned int uiSubmenu::getNumItems() const
{
	if(items)
		return items->getNumEntities();
	
	return 0;
}

uiSubmenuItem* uiSubmenu::getItem(unsigned int i) const
{
	if(items)
		return (uiSubmenuItem*)items->getEntity(i);
	
	return NULL; 
}
